package com.yhc.controller;

import com.google.gson.Gson;
import com.yhc.dao.User;
import com.yhc.dao.impl.UserImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author yhc
 * @create 2021-07-12-22:52
 */
@Controller
public class UserController {
    @RequestMapping("/ha")
    public String save(){
        System.out.println("i'm comming");
        return "haha.jsp";
    }

    @RequestMapping("/quick")
    public ModelAndView doSome(){
        ModelAndView modelAndView =new ModelAndView();
        modelAndView.setViewName("haha.jsp");
        modelAndView.addObject("username","nidie");
        return modelAndView;
    }
    @RequestMapping("/body")
    @ResponseBody
    public String body(){
        return "nimasila!!!!";
    }

    @RequestMapping("/test")
    @ResponseBody
    public UserImpl testJson(){
        Gson gson =new Gson();
        UserImpl user = new UserImpl("yhc",12);
        String o=gson.toJson(user, UserImpl.class);
        System.out.println(o);
        return user;
    }

    @RequestMapping("restful/{name}")
    public void rt(@PathVariable("name") String name){
        System.out.println( name);
    }
}
